﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

namespace Golf.WebUI.AdminShow.CouponsManagement
{
    public partial class RebateLogModify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int Id = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(Id);
                }
            }
        }

        private void ShowInfo(int Id)
        {
            Golf.BLL.Golf_RebateLog bll = new Golf.BLL.Golf_RebateLog();
            Golf.Model.Golf_RebateLog model = bll.GetModel(Id);
            this.lblId.Text = model.Id.ToString();
            this.txtUserId.Text = model.UserId.ToString();
            this.txtOrderId.Text = model.OrderId.ToString();
            this.txtOrderNumber.Text = model.OrderNumber;
            this.txtRebateType.Text = model.RebateType.ToString();
            this.txtCouponsNumber.Text = model.CouponsNumber;
            this.txtRemark.Text = model.Remark;
            this.txtCreateTime.Text = model.CreateTime.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (!PageValidate.IsNumber(txtUserId.Text))
            {
                strErr += "会员id Golf_User格式错误！\\n";
            }
            if (!PageValidate.IsNumber(txtOrderId.Text))
            {
                strErr += "订单id	Golf_User表格式错误！\\n";
            }
            if (this.txtOrderNumber.Text.Trim().Length == 0)
            {
                strErr += "订单号	Golf_User表不能为空！\\n";
            }
            if (!PageValidate.IsNumber(txtRebateType.Text))
            {
                strErr += "返券类型 1注册 2活动格式错误！\\n";
            }
            if (this.txtCouponsNumber.Text.Trim().Length == 0)
            {
                strErr += "优惠券编号不能为空！\\n";
            }
            if (this.txtRemark.Text.Trim().Length == 0)
            {
                strErr += "备注不能为空！\\n";
            }
            if (!PageValidate.IsDateTime(txtCreateTime.Text))
            {
                strErr += "创建时间格式错误！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int Id = int.Parse(this.lblId.Text);
            int UserId = int.Parse(this.txtUserId.Text);
            int OrderId = int.Parse(this.txtOrderId.Text);
            string OrderNumber = this.txtOrderNumber.Text;
            int RebateType = int.Parse(this.txtRebateType.Text);
            string CouponsNumber = this.txtCouponsNumber.Text;
            string Remark = this.txtRemark.Text;
            DateTime CreateTime = DateTime.Parse(this.txtCreateTime.Text);


            Golf.Model.Golf_RebateLog model = new Golf.Model.Golf_RebateLog();
            model.Id = Id;
            model.UserId = UserId;
            model.OrderId = OrderId;
            model.OrderNumber = OrderNumber;
            model.RebateType = RebateType;
            model.CouponsNumber = CouponsNumber;
            model.Remark = Remark;
            model.CreateTime = CreateTime;

            Golf.BLL.Golf_RebateLog bll = new Golf.BLL.Golf_RebateLog();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}